﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="EventLogs.aspx.cs" Inherits="EventLogs" Title="Untitled Page" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="content">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div style="background-color: White">
                <asp:LinkButton ID="lbFirst" runat="server" CommandName="changePage" CommandArgument="1"
                    OnCommand="changePage">First</asp:LinkButton>
                <asp:LinkButton ID="lbPrev" runat="server" CommandName="changePage" OnLoad="lbPrev_Load"
                    OnCommand="changePage">Prev</asp:LinkButton>
                Page:
                <asp:DropDownList ID="ddlPage" runat="server" AutoPostBack="true" OnLoad="ddlPage_Load"
                    OnSelectedIndexChanged="ddlPage_SelectedIndexChanged" />
                /
                <%=PagesCount %>
                <asp:LinkButton ID="lbNext" runat="server" CommandName="changePage" OnLoad="lbNext_Load"
                    OnCommand="changePage">Next</asp:LinkButton>
                <asp:LinkButton ID="lbLast" runat="server" CommandName="changePage" OnLoad="lbLast_Load"
                    OnCommand="changePage">Last</asp:LinkButton>
                Sorted by
                <%=SortField%>
                <%=SortDirection.ToString() %>
                <asp:Panel ID="panFilterCaption" runat="server" BackColor="Gray">
                    Filter</asp:Panel>
                <asp:Panel ID="panFilter" runat="server">
                    Entry types:<asp:CheckBoxList ID="cblEntryTypes" runat="server" OnLoad="cblEntryTypes_Load"
                        RepeatDirection="Horizontal" RepeatLayout="Flow">
                    </asp:CheckBoxList>
                    <br />
                    Source:<asp:DropDownList ID="ddlSource" runat="server" AppendDataBoundItems="True">
                        <asp:ListItem Selected="True">(All sources)</asp:ListItem>
                    </asp:DropDownList>
                    <br />
                    User:<asp:DropDownList ID="ddlUser" runat="server" AppendDataBoundItems="True">
                        <asp:ListItem Selected="True">(All users)</asp:ListItem>
                        <asp:ListItem>(No user)</asp:ListItem>
                    </asp:DropDownList>
                    <asp:Button ID="btnApplyFilter" runat="server" OnClick="btnApplyFilter_Click" Text="Apply filter" />
                </asp:Panel>
                <cc2:CollapsiblePanelExtender ID="colPanFilter" runat="server" TargetControlID="panFilter"
                    CollapseControlID="panFilterCaption" ExpandControlID="panFilterCaption" />
            </div>
            <asp:ListView ID="lvEvents" runat="server">
                <LayoutTemplate>
                    <table style="width: 100%">
                        <thead>
                            <tr style="background-color: Gray">
                                <th>
                                    <asp:LinkButton ID="lbSortType" runat="server" CommandName="sortOrder" CommandArgument="Type"
                                        OnCommand="Sort">Type</asp:LinkButton>
                                </th>
                                <th>
                                    <asp:LinkButton ID="lbSortTime" runat="server" CommandName="sortOrder" CommandArgument="Time"
                                        OnCommand="Sort">Time</asp:LinkButton>
                                </th>
                                <th>
                                    <asp:LinkButton ID="lbSortSource" runat="server" CommandName="sortOrder" CommandArgument="Source"
                                        OnCommand="Sort">Source</asp:LinkButton>
                                </th>
                                <th>
                                    <asp:LinkButton ID="lbSortUser" runat="server" CommandName="sortOrder" CommandArgument="User"
                                        OnCommand="Sort">User</asp:LinkButton>
                                </th>
                                <th>
                                    <asp:LinkButton ID="lbSortMachine" runat="server" CommandName="sortOrder" CommandArgument="Machine"
                                        OnCommand="Sort">Machine</asp:LinkButton>
                                </th>
                                <th>
                                    More
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr id="itemPlaceholder" runat="server" />
                        </tbody>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr style="background-color: White">
                        <td>
                            <asp:Image ID="imgType" runat="server" ImageUrl='<%#Eval("EntryType","~/Images/EventLogs/{0}.JPG")%>' />
                        </td>
                        <td>
                            <%#Eval("TimeWritten")%>
                        </td>
                        <td>
                            <%#Eval("Source") %>
                        </td>
                        <td>
                            <%#Eval("UserName") %>
                        </td>
                        <td>
                            <%#Eval("MachineName") %>
                        </td>
                        <td>
                            <asp:HyperLink ID="hlMore" runat="server" NavigateUrl='<%#GetMoreUrl(Container.DataItem)%>'>More</asp:HyperLink>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:ListView>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:Panel ID="panEntry" runat="server" BackColor="White" ScrollBars="Auto" Height="450px" Width="600px">
    <asp:Panel ID="panEntryBar" runat="server" BackColor="LightBlue" Width="100%" Height="21px">
    Event</asp:Panel>
        <table style="width: 100%; background-color:White">
            <tr>
                <td class="entry_prop">
                    Entry type
                </td>
                <td>
                    <asp:Label ID="labType" runat="server" />
                </td>
            </tr>
            
            <tr>
                <td class="entry_prop">
                    Time
                </td>
                <td>
                    <asp:Label ID="labTime" runat="server" />
                </td>
            </tr>
            
             <tr>
                <td class="entry_prop">
                    Source
                </td>
                <td>
                    <asp:Label ID="labSource" runat="server" />
                </td>
            </tr>
            
             <tr>
                <td class="entry_prop">
                    User
                </td>
                <td>
                    <asp:Label ID="labUser" runat="server" />
                </td>
            </tr>
            
             <tr>
                <td class="entry_prop">
                    Category
                </td>
                <td>
                    <asp:Label ID="labCategory" runat="server" />
                </td>
            </tr>
             
             <tr>
                <td class="entry_prop">
                    Computer
                </td>
                <td>
                    <asp:Label ID="labComputer" runat="server" />
                </td>
            </tr>
            <tr>
                <td colspan="2" class="entry_prop">
                    Message:
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <pre id="preMsg" style="width:590px; overflow: scroll; max-height:200px" /></td></tr></table><asp:Button ID="btnClose" runat="server" Text="Close" />
    </asp:Panel>
    <cc2:ModalPopupExtender ID="modalEntry" runat="server" PopupControlID="panEntry"
        TargetControlID="panEntry" OkControlID="btnClose" OnOkScript="HideModalPopup()"/>
</asp:Content>
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="head">
    <script type="text/javascript">
function more(index,log)
{
    document.getElementById('ctl00_updateProgress').style.visibility='visible';
    EventWS.GetEntry(index,log,DisplayResult);
}

function DisplayResult(result)
{
    var doc; 
    if (window.ActiveXObject) 
    { 
        doc=new ActiveXObject("Microsoft.XMLDOM"); 
        doc.async="false"; 
        doc.loadXML(result); 
    } 
    else 
    { 
        var parser=new DOMParser(); 
        var doc=parser.parseFromString(result,"text/xml"); 
    } 

    var tags=doc.documentElement.childNodes; 
    
    for(var i=0;i<tags.length;i++) 
    {     
        if (tags[i].nodeType==1) 
        {                                                 
            if(tags[i].childNodes[0]!=undefined)
            {
                var xmlvalue=tags[i].childNodes[0].nodeValue; 
            }

            switch (tags[i].nodeName) 
            { 
                case "type":
                    document.getElementById('<%=labType.ClientID %>').innerHTML=xmlvalue;
                    break;
                case "time":
                    document.getElementById('<%=labTime.ClientID %>').innerHTML=xmlvalue;
                    break;
                case "source":
                    document.getElementById('<%=labSource.ClientID %>').innerHTML=xmlvalue;
                    break;
                case "user":
                    document.getElementById('<%=labUser.ClientID %>').innerHTML=xmlvalue;
                    break;
                case "category":
                    document.getElementById('<%=labCategory.ClientID %>').innerHTML=xmlvalue;
                    break;
                case "computer":
                    document.getElementById('<%=labComputer.ClientID %>').innerHTML=xmlvalue;
                    break;
                case "message":                                                                        
                    document.getElementById('preMsg').innerHTML=xmlvalue;
                    break;
            }
        }
    }
    
    document.getElementById('ctl00_updateProgress').style.visibility='hidden';
    
    var modal=$find('<%= modalEntry.ClientID %>');                
    modal.show();
}

function HideModalPopup()
{
    var modal=$find('<%= modalEntry.ClientID %>');                
    modal.hide();
}
    </script>
<style type="text/css">
    td.entry_prop
    {
        font-weight: bold;        
        background-color: #C0C0C0;
        width:25%;
    }
</style>
</asp:Content>
